<?php
require_once 'Zend/Validate/Abstract.php';

class My_Validator_ISBNLength extends Zend_Validate_Abstract {
    const NOT_MATCH = 'ISBNLenthNotMatch';

    protected $_messageTemplates = array(
        self::NOT_MATCH => 'ISBN must be either 10 or 13 characters'
    );

    /**
     * Check if the element using this validator is valid
     *
     * This method will compare the $value of the element to the other elements
     * it needs to match. If they all match, the method returns true.
     *
     * @param $value string
     * @param $context array All other elements from the form
     * @return boolean Returns true if the element is valid
     */
    public function isValid($value, $context = null) {
        $value = (string) $value;
        $this->_setValue($value);

        $error = true;

        if (strlen($value) == 10 || strlen($value) == 13) {
        	$error = false;
        }
        $this->_error ( self::NOT_MATCH );
        return !$error;
    }
}
